package com.ict.web.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ict.web.domain.CloudResourceRequirement;
import com.ict.web.dto.InsertCloudResourceDto;
import com.ict.web.dto.UpdateCloudResourceDto;
import com.ict.web.mapper.CloudResourceRequirementMapper;
import com.ict.web.service.ICloudResourceRequirementService;
import com.ict.web.vo.CloudResourceRequirementVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

import java.util.List;


/**
 * 云资源需求Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-03-07
 */
@Service
public class CloudResourceRequirementServiceImpl extends ServiceImpl<CloudResourceRequirementMapper, CloudResourceRequirement> implements ICloudResourceRequirementService
{
    @Autowired
    private CloudResourceRequirementMapper cloudResourceRequirementMapper;


    /**
     * 获取云资源需求需求
     * @param cloudResourceId 云资源需求主键
     * @return
     */
    @Override
    public CloudResourceRequirement selectCloudResourceRequirementByCloudResourceId(Long cloudResourceId) {
        return cloudResourceRequirementMapper.selectCloudResourceRequirementById(cloudResourceId);
    }

    /**
     * 查询云资源需求列表
     * @return
     */
    @Override
    public List<CloudResourceRequirement> selectCloudResourceRequirementList() {

        return cloudResourceRequirementMapper.selectCloudResourceRequirementList();
    }

    /**
     * 新增云资源需求
     * @param programmeId
     * @param addDto 云资源需求
     * @return
     */
    @Override
    public int insertCloudResourceRequirement(Long programmeId, InsertCloudResourceDto addDto) {
        CloudResourceRequirement bean = InsertCloudResourceDto.of(addDto);
        bean.setProgrammeId(programmeId);
        int result = cloudResourceRequirementMapper.insert(bean);
        Assert.isTrue(result > 0 ,"新增云资源需求失败!!!");
        return result;
    }

    /**
     * 更新云资源需求
     * @param updateDto 云资源需求
     * @return
     */
    @Override
    public int updateCloudResourceRequirement(UpdateCloudResourceDto updateDto) {
        CloudResourceRequirement bean = UpdateCloudResourceDto.of(updateDto);
        CloudResourceRequirement resourceRequirement = this.getById(updateDto.getCloudResourceId());
        Assert.isTrue(resourceRequirement != null &&!(resourceRequirement.getDelFlag().equals(CloudResourceRequirement.DELETE_STATUS_UNNORMAL)),
                "未找到数据!!!");
         return cloudResourceRequirementMapper.updateById(bean);
    }

    /**
     * 删除云资源需求
     * @param cloudResourceId 云资源需求主键
     * @return
     */
    @Override
    public int deleteCloudResourceRequirementById(Long cloudResourceId) {
        return cloudResourceRequirementMapper.deleteCloudResourceRequirementById(cloudResourceId);
    }

    @Override
    public List<CloudResourceRequirementVo> selectCloudResourceListByProgrammeIds(Long programmeId) {
        return cloudResourceRequirementMapper.selectCloudResourceListByProgrammeIds(programmeId);
    }
}
